using CommonServiceLocator.SpringAdapter;
using log4net.Config;
using Microsoft.Practices.ServiceLocation;
using Spring.Context.Support;

namespace SIP.PN.Infraestructura.Initializer
{
	public static class Initializer
	{
		public static void StartUp()
        {
			IInitializer[] initializers = GetInitializers();

			for (int i = 0; i < initializers.Length; i++)
				initializers[i].StartUp();
        }

		public static void ShutDown()
		{
			IInitializer[] initializers = GetInitializers();

			for (int i = initializers.Length - 1; i >= 0; i--)
				initializers[i].ShutDown();
		}

		private static IInitializer[] GetInitializers()
		{
			IInitializer[] list = new IInitializer[2];
			list[0] = new Log4NetInitializer();
			list[1] = new SpringInitializer();

			return list;
		}
	}

	public interface IInitializer
	{
		void StartUp();
		void ShutDown();
	}

	public class SpringInitializer : IInitializer
	{
		public void StartUp()
		{
			ServiceLocator.SetLocatorProvider(delegate { return new SpringServiceLocatorAdapter(ContextRegistry.GetContext()); });
		}

		public void ShutDown()
		{
			
		}
	}

	public class Log4NetInitializer : IInitializer
	{
		public void StartUp()
		{
			XmlConfigurator.Configure();
		}

		public void ShutDown()
		{
			
		}
	}
}